#include "Array.h"
#include <iostream>
using namespace std;

Array &Array::operator=(const Array &a)
{
    if (this->ptr != nullptr && size == a.size)
    {
        for (int i = 0; i < size; i++)
        {
            ptr[i] = a.ptr[i];
        }
        return *this;
    }
    // 复制新内存之前要释放原有的内存空间
    else
    {
        if (this != &a)
        {
            delete[] ptr;
        }
        size = a.size;
        ptr = new Node[size];
        for (int i = 0; i < size; i++)
        {
            ptr[i] = a.ptr[i];
        }
        return *this;
    }
}
Array::Array(const Array &a)
{
    if (this->ptr != nullptr && size == a.size)
    {
        for (int i = 0; i < size; i++)
        {
            ptr[i] = a.ptr[i];
        }
    }
    else
    {
        if (this != &a)
        {
            delete[] ptr;
        }
        size = a.size;
        ptr = new Node[size];
        for (int i = 0; i < size; i++)
        {
            ptr[i] = a.ptr[i];
        }
    }
}
Array &Array::operator=(Array &&a)
{
    size = a.size;
    ptr = a.ptr;
    a.ptr = nullptr;
    return *this;
}
Array::Array(Array &&a)
{
    size = a.size;
    ptr = a.ptr;
    a.ptr = nullptr;
}